<template>
    <div>
        <div style="height: 50px;background-color: #3763A6">
            <img src="../../assets/img/deployment/policeDevelopTitle.png" class="" style="height: 100%" alt="">
        </div>

        <div class="d-flex">

            <div class="w-100 d-flex flex-column">
                <div class="p-6 flex-no-zoom">
                    <DeploymentSearch @noSearchForm="noSearchForm" @exportExcel="exportExcel"></DeploymentSearch>
                </div>

                <div class="d-flex mx-6 mb-6 h-100">

                    <div class="partBgBox w-100 py-6 px-10">
                        <div class="flexCenterBetween">
                            <div>
                                <div class="flexCenter">
                                    <div class="titleBefore"></div>
                                    <div>警力安排</div>
                                </div>
                            </div>

                            <div>
                                <!--<a-button type="primary" size="small">-->
                                    <!--保存-->
                                <!--</a-button>-->
                            </div>

                        </div>

                        <div class="mt-6">
                            <a-table :columns="policeDutyColumns" :data-source="policeDutyList" size="small"
                                     :pagination="false" :scroll="{ y:ws.wh-414-242}"
                                     :customRow="rowClick"
                                     :rowClassName="rowClassName">

                                    <span slot="timeRange" slot-scope="record">
                                        <span v-if="record.main">{{record.startTimeP + '-' + record.endTimeP}}</span>
                                         <a-button type="primary" ghost class="px-4 ml-4" size="small"
                                                   @click="splitTime(record)"
                                                   v-if="record.main">分</a-button>
                                    </span>


                                <span slot="timeDetailRange" slot-scope="record">
                                        <span v-if="record.startTime">{{record.startTime + '-' + record.endTime}}</span>

                                         <a-popconfirm title="确认删除?" ok-text="确定" cancel-text="取消"
                                                       @confirm="deleteItem(record)" v-if="!record.main">
                                             <a-button type="danger" ghost class="px-6 ml-4"
                                                       size="small">X</a-button></a-popconfirm>
                                    </span>

                                <a-button-group slot="action" slot-scope="text,record" size="small" v-if="canEdit(record)">
                                    <a-button @click="arrangePoliceCar(record,$event)"
                                              :type="record.policeCar?'':'primary'">安排警车
                                    </a-button>
                                    <a-button @click="arrangePolice(record,$event)"
                                              :type="record.policeIds?'':'primary'">
                                        安排警员
                                    </a-button>
                                </a-button-group>
                                <!--<span slot="action" slot-scope="text,record">-->
                                <!--<a href="#" @click="arrangePoliceCar(record)">安排警车</a>-->
                                <!--<a-divider type="vertical"/>-->
                                <!--<a href="#" @click="arrangePolice(record)">安排警员</a>-->
                                <!--</span>-->

                            </a-table>
                        </div>

                    </div>
                </div>
                <div class=" w-100 pb-6">
                    <div class="partBgBox mx-6  py-6 px-10">
                        <SecurityRiskAnalysis ref="securityRiskAnalysis" type="police"></SecurityRiskAnalysis>
                    </div>
                </div>
            </div>

            <DeploymentMap :searchParams="searchParams"></DeploymentMap>
        </div>

        <Jmodal :visible="splitTimeModalVisible" title="时间细分" left="50%" width="200" top="120"
                @cancel="splitTimeModalVisible = false">

            <div>
                <div class="mb-10">时间细分时间点</div>
                <a-time-picker :disabledHours="splitTimeDisabledHours" :disabledMinutes="splitTimeDisabledMinutes"
                               :minute-step="30" size="small"
                               format="HH:mm" v-model="splitTimeValue"/>
            </div>


            <div class="mt-14 text-center">
                <a-button size="small" class="mr-14" @click="splitTimeModalVisible = false">
                    取消
                </a-button>
                <a-button type="primary" size="small" @click="splitTimeModalSubmit">
                    确定
                </a-button>

            </div>

        </Jmodal>


        <Jmodal :visible="positionPoliceModalVisible" title="安排警员" right="100" width="454" top="120"
                @cancel="positionPoliceModalVisible = false">

            <div class="d-flex">
                <div class="mr-10">
                    <div>民警</div>
                    <table class="border" style="width:210px">
                        <thead class="bg-light">
                        <tr>
                            <td class="px-6 py-4"></td>
                            <td class="px-6 py-4">警号</td>
                            <td class="px-6 py-4">姓名</td>
                        </tr>
                        </thead>

                        <tbody class="">
                        <tr v-for="(item,i) in polices" :key="i" v-if="item.type == 1">
                            <td class="px-6 py-4 border-top">
                                <a-checkbox v-model="item.checked">
                                </a-checkbox>
                            </td>
                            <td class="px-6 py-4 border-top">{{item.policeid}}</td>
                            <td class="px-6 py-4 border-top">{{item.policename}}</td>
                        </tr>
                        </tbody>
                    </table>
                    <div class="mt-6">已选民警</div>
                    <div class="d-flex flex-wrap">

                        <a-tag class="mt-4" color="blue" closable @close="item.checked=false"
                               v-for="(item,i) in polices" :key="i" v-if="item.checked&&item.type == 1">
                            {{item.policename}}
                        </a-tag>

                    </div>

                </div>
                <div>
                    <div>辅警</div>
                    <table class="border" style="width:210px">
                        <thead class="bg-light">
                        <tr>
                            <td class="px-6 py-4"></td>
                            <td class="px-6 py-4">警号</td>
                            <td class="px-6 py-4">姓名</td>
                        </tr>
                        </thead>

                        <tbody class="">
                        <tr v-for="(item,i) in polices" :key="i" v-if="item.type == 0">
                            <td class="px-6 py-4 border-top">
                                <a-checkbox v-model="item.checked">
                                </a-checkbox>
                            </td>
                            <td class="px-6 py-4 border-top">{{item.policeid}}</td>
                            <td class="px-6 py-4 border-top">{{item.policename}}</td>
                        </tr>
                        </tbody>
                    </table>
                    <div class="mt-6">已选辅警</div>
                    <div class="d-flex flex-wrap">

                        <a-tag class="mt-4" color="blue" closable @close="item.checked=false"
                               v-for="(item,i) in polices" :key="i" v-if="item.checked&&item.type == 0">
                            {{item.policename}}
                        </a-tag>

                    </div>
                </div>
            </div>


            <div class="mt-14 text-center">
                <a-button size="small" class="mr-14" @click="positionPoliceModalVisible = false">
                    取消
                </a-button>
                <a-button type="primary" size="small" @click="positionPoliceModalSubmit">
                    确定
                </a-button>

            </div>

        </Jmodal>

        <Jmodal :visible="positionCarModalVisible" title="安排警车" right="100" width="300" top="120"
                @cancel="positionCarModalVisible = false">


            <a-radio-group v-model="positionCarId" class="d-flex flex-wrap" style="max-height: 600px;overflow-y: auto">
                <a-radio style="display:block;margin:6px 10px;" v-for="(item,i) in positionCarList" :key="i"
                         :value="item.policecar">
                    {{item.policecar}}
                </a-radio>

            </a-radio-group>

            <div class="mt-14 text-center">
                <a-button size="small" class="mr-14" @click="positionCarModalVisible = false">
                    取消
                </a-button>
                <a-button type="primary" size="small" @click="positionCarModalSubmit">
                    确定
                </a-button>

            </div>

        </Jmodal>


    </div>

</template>

<script>
    import DeploymentSearch from "@/components/deployment-search.vue";
    import SecurityRiskAnalysis from "@/components/deployment/security-risk-analysis.vue";
    import Jmodal from "@/components/jmodal.vue";
    import DeploymentMap from "@/components/deployment/deployment-map.vue";
    import * as moment from "moment";
    import * as XLSX from "xlsx-style";
    import {s2ab,saveAs} from "../../utils/sys_utils";
    import {
        addPositionPolice,
        deletePositionPolice,
        getPoliceCar,
        getPoliceDutyList, getPolicList, login,
    } from "../../common/api";
    import {sysDic} from "../../common/filters";
    import {getDictByTypeValue} from "../../utils/sys-dic-utils";
    import store from "@/common/vuex";

    export default {
        name: "police-deployment",
        components: {DeploymentSearch, SecurityRiskAnalysis, Jmodal, DeploymentMap},
        filters: {sysDic},
        data() {
            return {
                selectedRow: null, // 选中那一行查看部署
                policeDutyColumns: [{
                    title: '日期',
                    dataIndex: 'currentTime',
                    key: 'currentTime',
                    align: 'center', customRender: (text, record, index) => {
                        if (record.main) {
                            return text;
                        } else {
                            return ""
                        }

                    }
                },
                    {
                        title: '岗位类型',
                        dataIndex: 'type',
                        key: 'type',
                        width: 70,
                        align: 'center',
                        customRender: (text, record, index) => {
                            if (record.main) {
                                return getDictByTypeValue('dutyType', text).label
                            } else {
                                return ""
                            }

                        }
                    }, {
                        title: '岗位名称',
                        dataIndex: 'name',
                        key: 'name',
                        align: 'center',
                        customRender: (text, record, index) => {
                            if (record.main) {
                                return text;
                            } else {
                                return ""
                            }

                        }
                    }, {
                        title: '所属部门',
                        dataIndex: 'midDeptName',
                        key: 'midDeptName',
                        align: 'center',
                        customRender: (text, record, index) => {
                            if (record.main) {
                                return text;
                            } else {
                                return ""
                            }

                        }
                    }, {
                        title: '岗位范围',
                        dataIndex: 'position',
                        key: 'position',
                        customRender: (text, record, index) => {
                            if (record.main) {
                                return text
                            } else {
                                return ""
                            }
                        }
                    }, {
                        title: '岗位时段',
                        dataIndex: '',
                        key: 'startTime',
                        scopedSlots: {customRender: 'timeRange'},

                    }, {
                        title: '细分时段',
                        dataIndex: '',
                        key: 'timeEnd',
                        scopedSlots: {customRender: 'timeDetailRange'},

                    }, {
                        title: '警车',
                        dataIndex: 'policeCar',
                        key: 'policeCar',

                    }, {
                        title: '警员',
                        dataIndex: 'policeNames',
                        key: 'policeNames',

                    }, {
                        title: '操作',
                        dataIndex: 'action',
                        key: 'action',
                        scopedSlots: {customRender: 'action'},
                    },
                ],
                policeDutyList: [],
                searchParams: {}, //查询条件

                //时间细分
                splitTimeModalVisible: false,
                splitTimeFrom: {},
                splitTimeValue: "",
                splitTimeDisabledHours: () => {
                },
                splitTimeDisabledMinutes: (hours) => {
                },

                //警力添加
                positionPoliceModalVisible: false,
                polices: [],  //警察
                // polices1: [], //民警

                //警车安排
                positionCarModalVisible: false,
                positionCarId: "",
                positionCarList: [],
            }
        },
        computed: {
            ws() {
                return this.$store.state.ws
            },
        },
        methods: {

            noSearchForm(reqBody) {  //查询
                this.searchParams = reqBody;
                this.getPoliceDutyList(true);


            },
            getPoliceDutyList(flag = false) { //获取列表
                this.$message.loading({content: '查询中...', key: 'loading1', duration: 0});
                // reqBody.motorwayId = '4'   //高速id
                // reqBody.startTime = '2020-11-18'  //开始时间
                // reqBody.endTime = '2020-11-30'   //结束时间
                getPoliceDutyList(this.searchParams).then(res => {
                    if (res.isSuccess) {
                        this.$message.success({content: '查询成功...', key: 'loading1'});
                        this.policeDutyList = this.formatListData(res.data);
                        this.policeDutyList.forEach((v, i) => {
                            v.index = i
                        })

                        if (flag) {
                            this.$refs.securityRiskAnalysis.getCoverageRate(this.searchParams, {currentTime: this.policeDutyList[0].currentTime})
                            this.$refs.securityRiskAnalysis.getSecurityRiskAnalysisList(this.searchParams, {currentTime: this.policeDutyList[0].currentTime})
                        }
                    }
                })
            },

            formatListData(data) {
                const d = [];
                data.forEach((v, i) => {
                    const item = {
                        positionId: v.id,
                        type: v.type,
                        name: v.name,
                        deptName: v.deptName,
                        deptId: v.deptId,
                        midDeptName: v.midDeptName,
                        midDeptId: v.midDeptId,
                        startTimeP: v.startTime,
                        endTimeP: v.endTime,
                        currentTime: v.currentTime,
                        position: v.position,
                        main: true,
                        rowSpan: v.deploy ? v.deploy.length : 1,
                    };
                    if (v.deploy && v.deploy.length > 0) {
                        v.deploy.forEach((w, i1) => {
                            var item2 = Object.assign({}, item);
                            if (i1 > 0) {
                                item2.main = false;
                            }
                            // console.log(111)
                            // console.log(w.startTime)
                            // console.log(w.endTime)
                            item2.startTime = moment(w.startTime).format('HH:mm');
                            item2.endTime = moment(w.endTime).format('HH:mm');

                            console.log(item2.startTime)
                            console.log(item2.endTime)

                            item2.policeNames = w.policeNames;
                            item2.id = w.id;
                            item2.policeIds = w.policeIds;
                            item2.policeCar = w.policeCar;

                            d.push(item2);
                        })

                    } else {
                        item.endTime = v.endTime;
                        item.startTime = v.startTime;
                        d.push(item);
                    }

                });
                return d
            },

            arrangePoliceCar(item, $event) { //安排警车
                $event.stopPropagation();
                this.$message.loading({content: '警车查询中...', key: 'loading1', duration: 0});
                this.splitTimeFrom = item;
                this.positionCarId = item.policeCar;
                const requstBody = {
                    id:item.id,
                    deptId: item.deptId,   // 大队ID
                    middeptId: item.midDeptId, //中队ID
                    startTime: item.currentTime + ' ' + (item.startTime ? item.startTime : item.startTimeP),//开始时间
                    endTime: item.currentTime + ' ' + (item.endTime ? item.endTime : item.endTimeP),//结束时间
                };
                getPoliceCar(requstBody).then(res => {
                    if (res.isSuccess) {
                        if (res.data && res.data.length == 0) {
                            this.$message.warn({content: '没有查询到警车！', key: 'loading1'});
                            return;
                        }
                        this.positionCarList = res.data;
                        this.positionCarId = "";
                        this.positionCarList.forEach(v => {
                            if (item.policeCar == v.policecar) {
                                v.checked = true;
                            }
                        })
                        this.positionCarModalVisible = true;
                        this.$message.success({content: '警车查询成功！', key: 'loading1'});

                    } else {
                        this.$message.error({content: '警车查询失败！', key: 'loading1'});
                    }
                })

            },
            arrangePolice(item, $event) {  //安排警察
                $event.stopPropagation();
                // console.log(item)
                this.$message.loading({content: '警察查询中...', key: 'loading1', duration: 0});
                this.splitTimeFrom = item;
                var ids = [];
                if (item.policeIds) {
                    ids = item.policeIds.split(',');
                }
                const requstBody = {
                    id:item.id,
                    deptId: item.deptId,   // 大队ID
                    middeptId: item.midDeptId, //中队ID
                    startTime: item.currentTime + ' ' + (item.startTime ? item.startTime : item.startTimeP),//开始时间
                    endTime: item.currentTime + ' ' + (item.endTime ? item.endTime : item.endTimeP),//结束时间
                };
                getPolicList(requstBody).then(res => {
                    if (res.isSuccess) {
                        this.$message.success({content: '警察查询成功！', key: 'loading1'});
                        if (res.data && res.data.length == 0) {
                            this.$message.warn({content: '没有查询到警察！', key: 'loading1'});
                            return;
                        }
                        this.positionPoliceModalVisible = true;
                        this.polices = res.data; //0辅警  1民警
                        this.polices.forEach(v => {
                            if (ids.indexOf(v.policeid) > -1) {
                                v.checked = true;
                            }
                        })

                    } else {
                        this.$message.error({content: '警察查询失败！', key: 'loading1'});
                    }
                })
            },
            deleteItem(item) {  // 删除时间细分
                var updata = this.policeDutyList[item.index - 1];
                updata.endTime = item.endTime;

                var newPositions = [];
                this.policeDutyList.forEach((v) => {
                    if (v.positionId == item.positionId) {
                        newPositions.push(v);
                    }
                });
                newPositions.forEach((v, i) => {
                    v.index2 = i;
                });
                newPositions.splice(updata.index2 + 1, 1); // 删除下一条

                this.$message.loading({content: "数据删除中！", key: 'loading1', duration: 0});

                addPositionPolice(this.buildNewReqBody(updata, newPositions)).then(res => {
                    if (res.isSuccess) {
                        this.splitTimeModalVisible = false;
                        this.$message.success({content: "数据删除成功！", key: 'loading1'});
                        this.getPoliceDutyList();
                    } else {
                        this.splitTimeModalVisible = false;
                        this.$message.error({content: res.info ? res.info : "数据删除失败！", key: 'loading1'});
                    }
                })
            },

            splitTime(item) { //时间细分
                this.splitTimeModalVisible = true;
                this.splitTimeFrom = item;
                let startT = [];
                let endT = [];
                if (item.startTime) {
                    startT = item.startTime.split(':');
                    endT = item.endTime.split(':');
                } else {
                    startT = item.startTimeP.split(':');
                    endT = item.endTimeP.split(':');
                }
                this.splitTimeDisabledHours = () => {
                    const hours = [];
                    const start = startT[0] * 1;
                    const end = endT[0] * 1;
                    for (let i = 0; i < start; i++) {
                        hours.push(i)
                    }
                    for (let i = end + 1; i < 24; i++) {
                        hours.push(i)
                    }
                    return hours;

                };
                this.splitTimeDisabledMinutes = (hours) => {
                    const minutes = [];
                    if (hours == startT[0]) {
                        const start = startT[1] * 1;

                        for (let i = 0; i < start; i++) {
                            minutes.push(i)
                        }
                    }
                    if (hours == endT[0]) {
                        const end = endT[1] * 1;
                        for (let i = end + 1; i < 60; i++) {
                            minutes.push(i)
                        }
                    }
                    return minutes;
                }


                // splitTimeDisabledHours: () => {
                // },
                //     splitTimeDisabledMinutes: (hours) => {
                // },


            },
            splitTimeModalSubmit() { //时间细分保存
                // console.log(this.splitTimeFrom.index);
                // console.log();
                var splitTime = this.splitTimeValue.format("HH:mm");
                var newList = Object.assign({}, this.splitTimeFrom);
                // newList.id = null;
                // newList.main = false;
                newList.policeNames = null;
                newList.policeIds = null;
                newList.policeCar = null;
                newList.startTime = splitTime;

                if (this.splitTimeFrom.startTime) {  //细分过的时间
                    newList.endTime = this.splitTimeFrom.endTime;
                    this.splitTimeFrom.endTime = splitTime;
                } else { // 没有细分过时间
                    this.splitTimeFrom.startTime = this.splitTimeFrom.startTimeP
                    this.splitTimeFrom.endTime = splitTime

                    newList.endTime = this.splitTimeFrom.endTimeP;
                }

                // this.policeDutyList.splice(index+1,0,newList);
                // this.policeDutyList.forEach((v,i)=>{
                //     v.index = i;
                // });

                // console.log(this.splitTimeFrom);
                // console.log(newList);
                // this.$forceUpdate();


                this.$message.loading({content: "数据保存中！", key: 'loading1', duration: 0});
                addPositionPolice(this.buildPliceReqBody(this.splitTimeFrom, newList)).then(res => {
                    if (res.isSuccess) {
                        this.splitTimeModalVisible = false;
                        this.$message.success({content: "时间细分成功！", key: 'loading1'});
                        this.getPoliceDutyList();
                    } else {
                        this.splitTimeModalVisible = false;
                        this.$message.error({content: res.info ? res.info : "时间细分失败！", key: 'loading1'});
                    }
                })

            },

            positionPoliceModalSubmit() {  //警力添加保存

                var selectedPoliceIds = [];
                var selectedPoliceNames = [];
                var noPlice = true;
                this.polices.forEach(v => {
                    if (v.checked) {
                        selectedPoliceIds.push(v.policeid);
                        selectedPoliceNames.push(v.policename);
                        if (v.type == 1) {
                            noPlice = false;
                        }
                    }
                })
                if (noPlice) {
                    this.$message.error("请至少选择一个民警！")
                    return;
                }
                if (selectedPoliceIds.length == 0) {
                    this.$message.error("请选择警察！");
                    return;
                }
                this.splitTimeFrom.policeNames = selectedPoliceNames.join(',');
                this.splitTimeFrom.policeIds = selectedPoliceIds.join(',');

                this.$message.loading({content: "警察数据保存中！", key: 'loading1', duration: 0});
                addPositionPolice(this.buildPliceReqBody(this.splitTimeFrom)).then(res => {
                    if (res.isSuccess) {
                        this.positionPoliceModalVisible = false;
                        this.$message.success({content: "安排警察成功！", key: 'loading1'});
                        this.getPoliceDutyList();
                        this.$refs.securityRiskAnalysis.getCoverageRate(this.searchParams, {currentTime: this.splitTimeFrom.currentTime})
                        this.$refs.securityRiskAnalysis.getSecurityRiskAnalysisList(this.searchParams, {currentTime: this.splitTimeFrom.currentTime})
                    } else {
                        this.splitTimeModalVisible = false;
                        this.$message.error({content: res.info ? res.info : "安排警察失败！", key: 'loading1'});
                    }
                })
            },
            positionCarModalSubmit() {  //警车添加保存

                if (!this.positionCarId) {
                    this.$message.error("请选择警车！");
                    return;
                }
                this.splitTimeFrom.policeCar = this.positionCarId;
                this.$message.loading({content: "安排警车保存中！", key: 'loading1', duration: 0});
                addPositionPolice(this.buildPliceReqBody(this.splitTimeFrom)).then(res => {
                    if (res.isSuccess) {
                        this.positionCarModalVisible = false;
                        this.$message.success({content: "安排警车成功！", key: 'loading1'});
                        this.getPoliceDutyList();
                    } else {
                        this.splitTimeModalVisible = false;
                        this.$message.error({content: res.info ? res.info : "安排警车失败！", key: 'loading1'});
                    }
                })
            },
            rowClick(record, index) {
                // console.log('rowClick',index);
                return {
                    on: {
                        click: () => {
                            this.$refs.securityRiskAnalysis.getCoverageRate(this.searchParams, {currentTime:record.currentTime})
                            this.$refs.securityRiskAnalysis.getSecurityRiskAnalysisList(this.searchParams, {currentTime:record.currentTime})
                        }
                    }
                };
            },
            rowClassName(record) {
                let className = "cursorPionter";
                if (record == this.selectedRow) {
                    className = "rowActive cursorPionter";
                    this.$emit('change', this.selectedRow)
                }
                if (!record.policeIds) {
                    className += ' rowRed'
                }
                return className;
            },
            buildPliceReqBody(data, newList = null) {

                var newPositions = [];

                this.policeDutyList.forEach((v) => {
                    if (v.positionId == data.positionId) {
                        newPositions.push(v);
                    }
                });

                if (newList) {
                    newPositions.forEach((v, i) => {
                        v.index2 = i;
                    });
                    newPositions.splice(data.index2 + 1, 0, newList);
                }

                return this.buildNewReqBody(data, newPositions);
            },
            buildNewReqBody(data, newPositions) {
                var positionInfo = {
                    positionId: data.positionId,
                    deptId: data.deptId,
                    middeptId: data.midDeptId,
                    // startTime:data.startTimeP,
                    // endTime:data.startTimeP,
                    positions: [],
                };
                newPositions.forEach(v => {
                    var p = {
                        startTime: v.currentTime + ' ' + v.startTime,
                        endTime: v.currentTime + ' ' + v.endTime,
                        policeIds: v.policeIds,
                        policeCar: v.policeCar,
                        policeNames: v.policeNames,
                    };
                    positionInfo.positions.push(p);
                });
                return positionInfo
            },
            exportExcel(deptName) {
                //创建book
                // console.log(this.policeDutyList);
                this.$message.loading({content: '导出中...', key: 'loading1', duration: 0});
                // reqBody.motorwayId = '4'   //高速id
                // reqBody.startTime = '2020-11-18'  //开始时间
                // reqBody.endTime = '2020-11-30'   //结束时间
                getPoliceDutyList(this.searchParams).then(res => {
                    if (res.isSuccess) {
                        this.$message.success({content: '导出成功...', key: 'loading1'});
                        const dataTmp = this.formatListData(res.data);

                        var styleBase = {
                            border: { // 设置边框
                                top: { style: 'thin' },
                                bottom: { style: 'thin' },
                                left: { style: 'thin' },
                                right: { style: 'thin' }
                            },
                            alignment:{
                                vertical:"center"
                            }
                        };
                        const outPut = {
                            A1: {v:"序号",s:styleBase,},
                            B1: {v:"日期",s:styleBase,},
                            C1: {v:"岗位类型",s:styleBase,},
                            D1: {v:"岗位名称",s:styleBase,},
                            E1: {v:"所属部门",s:styleBase,},
                            F1: {v:"岗位范围",s:styleBase,},
                            G1: {v:"岗位时段",s:styleBase,},
                            H1: {v:"细分时段",s:styleBase,},
                            I1: {v:"警车",s:styleBase,},
                            J1: {v:"警员",s:styleBase,},
                        };
                        outPut["!merges"] = [
                        ];
                        let index = 1
                        dataTmp.forEach((v, i) => {
                            if (v.main) {
                                    outPut['A'+(i+2)]={v:index,s:styleBase};
                                    outPut['B'+(i+2)]={v:v.currentTime,s:styleBase};
                                    outPut['C'+(i+2)]={v:getDictByTypeValue('dutyType', v.type).label,s:styleBase};
                                    outPut['D'+(i+2)]={v:v.name,s:styleBase};
                                    outPut['E'+(i+2)]={v:v.midDeptName,s:styleBase};
                                    outPut['F'+(i+2)]={v:v.position,s:styleBase};
                                    outPut['G'+(i+2)]={v:(v.startTimeP + '-' + v.endTimeP),s:styleBase};
                                    outPut['H'+(i+2)]={v:(v.startTime + '-' + v.endTime),s:styleBase};
                                    outPut['I'+(i+2)]={v:v.policeCar,s:styleBase};
                                    outPut['J'+(i+2)]={v:v.policeNames,s:styleBase};

                                index+=1;
                                outPut["!merges"].push(
                                    { s: { c: 0, r: i+1 }, e: { c: 0, r: i+v.rowSpan } },
                                    { s: { c: 1, r: i+1 }, e: { c: 1, r: i+v.rowSpan } },
                                    { s: { c: 2, r: i+1 }, e: { c: 2, r: i+v.rowSpan } },
                                    { s: { c: 3, r: i+1 }, e: { c: 3, r: i+v.rowSpan } },
                                    { s: { c: 4, r: i+1 }, e: { c: 4, r: i+v.rowSpan } },
                                    { s: { c: 5, r: i+1 }, e: { c: 5, r: i+v.rowSpan } },
                                    { s: { c: 6, r: i+1 }, e: { c: 6, r: i+v.rowSpan } },
                                    )

                            } else {
                                outPut['A'+(i+2)]={v:"",s:styleBase};
                                outPut['B'+(i+2)]={v:"",s:styleBase};
                                outPut['C'+(i+2)]={v:"",s:styleBase};
                                outPut['D'+(i+2)]={v:"",s:styleBase};
                                outPut['E'+(i+2)]={v:"",s:styleBase};
                                outPut['F'+(i+2)]={v:"",s:styleBase};
                                outPut['G'+(i+2)]={v:"",s:styleBase};
                                outPut['H'+(i+2)]={v:v.startTime + '-' + v.endTime,s:styleBase};
                                outPut['I'+(i+2)]={v:v.policeCar,s:styleBase};
                                outPut['J'+(i+2)]={v:v.policeNames,s:styleBase};
                            }

                        });

                        outPut['!cols'] = [
                            {wch: 8},
                            {wch: 15},
                            {wch: 15},
                            {wch: 15},
                            {wch: 30},
                            {wch: 15},
                            {wch: 15},
                            {wch: 15},
                            {wch: 15}
                        ];

                        // console.log("ws");
                        // console.log(ws);

                        outPut['!ref'] =  'A1:J'+dataTmp.length+1;

                        var wb = {
                            SheetNames: ['Sheet1'],
                            Sheets: {
                                // Sheet1 表示工作簿名称
                                Sheet1: outPut
                            }
                        };
                        var tmpDown = new Blob([
                            s2ab(
                                // 这里的数据是用来定义导出的格式类型
                                XLSX.write(wb, {
                                    bookType: 'xlsx',
                                    bookSST: false,
                                    type: 'binary'
                                })
                            )
                        ], {
                            type: ""
                        });
                        saveAs(tmpDown,deptName+"部警详情.xlsx");
                    }
                })

            },
            canEdit(record) {
                if (moment().isBefore(record.currentTime + " " + record.startTime)) {
                    return true
                } else {
                    return false;
                }
            },
        }, mounted() {

        }, beforeRouteEnter(to, from, next) {
            console.log('beforeRouteEnter ---- ');
            if (!store.state.isLogin) {
                login().then((res) => {
                    if (res.isSuccess) {
                        store.commit("setLoginInfor", res.data);
                        next()
                    } else {
                        // alert("获取用户信息失败");
                        next()
                    }
                }).catch((e) => {
                    // alert("获取用户信息失败")
                    next();
                })
            } else {
                next()
            }
        },
    }
</script>

<style scoped>
    >>> .ant-table-small {
        border: none;
    }

    .fixednav {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
    }

    >>> .rowRed {
        color: red;
    }

</style>
